package com.casic.worklog.model.vo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 返回数据
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年10月27日 下午9:59:27
 */
public class Result extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

   /**请求成功*/
    public static final int STATUS_SUCCESS = 0;
    /**请求错误*/
    public static final int STATUS_ERROR = 1;

    public Result () {
        put("code", STATUS_SUCCESS);
        put("msg", "请求成功");


    }


    public static Result error() {
        return error(STATUS_ERROR, "未知异常，请联系管理员");
    }

    public static Result error(String msg) {
        return error(STATUS_ERROR, msg);
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    public static Result ok(Map<String, Object> map) {
        Result result = new Result();
        result.putAll(map);
        return result;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public Result put(Object value) {

        super.put("data", value);
        return this;
    }
}
